package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.ReposDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Reos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * 饮食管理
 */
@Service(interfaceClass = ReposService.class)
@Transactional
public class ReposServiceImpl implements ReposService {


    @Autowired
    private ReposDao reposDao;
//批量导入饮食数据
    @Override
    public void add(List<Reos> reosArrayList) {
        //健壮性判断
        if (reosArrayList != null && reosArrayList.size()>0){
            for (Reos reos : reosArrayList) {
                reposDao.add(reos);
            }
        }
    }
//添加饮食数据
    @Override
    public void addFood(Reos reos) {
        reposDao.add(reos);
    }
//分页查询
    @Override
    public PageResult findpageRepos(QueryPageBean queryPageBean) {
        //当前页
        Integer currentPage = queryPageBean.getCurrentPage();
        //每页显示条数
        Integer pageSize = queryPageBean.getPageSize();
        PageHelper.startPage(currentPage,pageSize);
        Page<Reos> page=reposDao.findpageRepos(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }
//回写数据
    @Override
    public Reos findAll(Integer id) {
        Reos reos=reposDao.findAll(id);
        return reos;
    }
//编辑饮食库数据
    @Override
    public void edit(Reos reos) {
        reposDao.edit(reos);
    }
//删除数据
    @Override
    public void del(Integer id) {
        reposDao.del(id);
    }
}
